﻿using HK.Core.Load.Protocol.Data;
using HLogger = HK.Core.Logs.Logger;

namespace HK.Core.Utils
{
    /// <summary>
    /// 监视时间
    /// </summary>
    public enum NotifyLoadEvent
    {
        /// <summary>
        /// 追加
        /// </summary>
        Add,
        
        /// <summary>
        /// 移除
        /// </summary>
        Remove,
        
        /// <summary>
        /// 刷新
        /// </summary>
        Refresh
    }
    
    /// <summary>
    /// 委托事件定义 : 通知加载监视
    /// </summary>
    /// <param name="iEvent">Event</param>
    /// <param name="iAssetInfo">Asset信息</param>
    public delegate void AssetLoadNotify(NotifyLoadEvent iEvent, IAssetInfo iAssetInfo);
    
    /// <summary>
    /// 委托事件定义 : 通知加载监视
    /// </summary>
    /// <param name="iEvent">Event</param>
    /// <param name="iEntityInfo">Entity信息</param>
    public delegate void EntityLoadNotify(NotifyLoadEvent iEvent, IEntityInfo iEntityInfo);
    
    /// <summary>
    /// 工具类 : 加载
    /// </summary>
    public static partial class UtilsLoad
    {
        
#region Events

        internal static AssetLoadNotify _assetNotify = (iEvent, iAssetInfo) =>
        {
#if UNITY_EDITOR
            // var descTmp = string.IsNullOrEmpty(desc) ? "-" : desc;
            // Loger.Info($"UtilsLoad::AssetNotify():{state}({target.Type}) - {target.Key}({descTmp})");
#endif
        };

        /// <summary>
        /// 通知事件 : Asset加载
        /// </summary>
        public static event AssetLoadNotify AssetNotify
        {

            add
            {
#if UNITY_EDITOR
                if (null != value)
                {
                    HLogger.Info($"AssetNotify(): + {value.Target.GetType().FullName}:{value.Method.Name}");
                }
#endif
                _assetNotify += value;
            }
            remove
            {

#if UNITY_EDITOR
                if (null != value)
                {
                    HLogger.Info("AssetNotify(): - {value.Target.GetType().FullName}:{value.Method.Name}");
                }
#endif
                if (null != _assetNotify) _assetNotify -= value;
            }
        }

        internal static EntityLoadNotify _entityNotify = (iEvent, iEntity) =>
        {
#if UNITY_EDITOR
            // var descTmp = string.IsNullOrEmpty(desc) ? "-" : desc;
            // Loger.Info($"UtilsLoad::EntityNotify():{state}({target.Type}) - {target.Key}({descTmp})");
#endif
        };

        /// <summary>
        /// 通知事件 : Asset加载
        /// </summary>
        public static event EntityLoadNotify EntityNotify
        {

            add
            {
#if UNITY_EDITOR
                if (null != value)
                {
                    HLogger.Info($"EntityNotify(): + {value.Target.GetType().FullName}:{value.Method.Name}");
                }
#endif
                _entityNotify += value;
            }
            remove
            {

#if UNITY_EDITOR
                if (null != value)
                {
                    HLogger.Info("EntityNotify(): - {value.Target.GetType().FullName}:{value.Method.Name}");
                }
#endif
                if (null != _entityNotify) _entityNotify -= value;
            }
        }
        
#endregion
        
    }
}
